<template>
  <el-tree
    :data="resTreeData"
    :show-checkbox="showCheckbox"
    node-key="id"
    :default-expanded-keys="[1]"
    :expand-on-click-node="false"
    @node-click="nodeClick"
    @check="onCheck"
    ref="resTree"
  >
    <span slot-scope="{ node, data }">
      <span>
        <i v-if="data.icon" :class="['fa','fa-'+data.icon]" style="color:#409EFF;width:18px;"></i>
        {{ data.name }}
      </span>
      <span style="color:#E6A23C">{{"【"+data.resTypeName+"】"}}</span>
    </span>
  </el-tree>
</template>

<script>
export default {
  props: {
    showCheckbox: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      resTreeData: []
    };
  },
  created() {
    this.getResByAdminId();
  },
  methods: {
    getResByAdminId() {
      let me = this;
      me.$http.ajax({
        url: "admin/getResByAdminId/" + me.$store.state.admin.id,
        success(res) {
          me.resTreeData = res;
        }
      });
    },
    onCheck(data, checkResult) {
      this.$emit("check", data, checkResult);
    },
    nodeClick(data, node, component) {
      this.$emit("node-click", data, node, component);
    },
    setCheckedKeys(keys) {
      this.$refs["resTree"].setCheckedKeys(keys);
    }
  }
};
</script>

<style>
</style>
